package com.bigger.controller;

import com.bigger.dto.OrderPageDTO;
import com.bigger.entity.Order;
import com.bigger.result.PageResult;
import com.bigger.result.Result;
import com.bigger.service.OrderService;
import com.bigger.vo.OrderDetailVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/runner/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("/get/{id}")
    public Result<OrderDetailVO> getById(@PathVariable("id") Long id){
        OrderDetailVO orderDetailVO = orderService.getById(id);
        return Result.success(orderDetailVO);
    }
    @PutMapping("/take")
    public Result<String> takeOrder(Long id){
        orderService.takeOrder(id);
        return Result.success("接单成功，请前往已接单处查看订单要求");
    }

    @PutMapping("/finish")
    public Result<String> finishOrder(Long id){
        orderService.finishOrder(id);
        return Result.success("订单已完成");
    }

    @GetMapping("/get")
    public Result<PageResult<Order>> page(OrderPageDTO orderPageDTO){
        PageResult<Order> orderPageResult=orderService.page(orderPageDTO);
        return Result.success(orderPageResult);
    }
}
